package cn.momoshenchi.service.impl;

import cn.momoshenchi.pojo.MatchOption;
import cn.momoshenchi.service.MatchOptionService;
import cn.momoshenchi.service.MatchUserHistoryService;
import cn.momoshenchi.util.ResultInfo;
import cn.momoshenchi.vo.MatchVo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.momoshenchi.pojo.MatchItems;
import cn.momoshenchi.service.MatchItemsService;
import cn.momoshenchi.mapper.MatchItemsMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 *
 */
@Service
public class MatchItemsServiceImpl extends ServiceImpl<MatchItemsMapper, MatchItems>
implements MatchItemsService{

    @Autowired
    private  MatchItemsMapper matchItemsMapper;

    @Autowired
    private MatchUserHistoryService matchUserHistoryService;

    @Autowired
    private MatchOptionService matchOptionService;


    @Override
    public List<MatchItems> getRandomList(Integer size)
    {
        return  matchItemsMapper.getRandomList(size);

    }

    @Override
    public List<MatchVo> getRandomTestList(Integer size)
    {
        List<MatchItems> matchItemsList  =this.getRandomList(size);
        List<Long>itemId=matchItemsList.stream().map(MatchItems::getId).collect(Collectors.toList());
        List<MatchOption>options=matchOptionService.getByMatchId(itemId);
        List<MatchVo>matchVoList=new ArrayList<>();
        for (MatchItems matchItems : matchItemsList)
        {
            MatchVo vo = new MatchVo();
            BeanUtils.copyProperties(matchItems,vo);
            for (MatchOption option : options)
            {
                if(option.getMatchId().equals(vo.getId()))
                {
                    vo.add(Character.toString(65+option.getSort())+". "+option.getTitle());
                }
            }
            matchVoList.add(vo);
        }
        return  matchVoList;
    }

}




